from models.models import Record
from service.BaseService import BaseService
from sqlmodel import Session, select
from core.Utils import generate_uuid
from typing import Optional
from datetime import datetime
class RecordService(BaseService[Record]):
    def __init__(self):
        super().__init__(Record)


    def get_all_by_machine_id(self, machine_id: str):
        statment = select(Record).where(Record.machine_id == machine_id)
        return self.session.exec(statment).all()

    def get_record_list(self,page: int, page_size: int, start_time: Optional[datetime],
                         record_id: Optional[str] = None, user_id: Optional[str] = None,
                         role_id: Optional[str] = None, end_time: Optional[datetime] = None):
        filters = []
        # 添加过滤条件
        if role_id not in (0,1):
            filters.append(Record.user_id == user_id)
        if  start_time is not None:
            filters.append(Record.create_time >= start_time)
        if end_time is not None:
            filters.append(Record.create_time <= end_time)
        if record_id is not None:
            filters.append(Record.record_id == record_id)
        # 获取分页数据
        record_list, total = self.get_paginated(page, page_size, filters)
        return record_list, total




